package org.lixf.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(8888);
        Socket accept = socket.accept();
        InputStream is = accept.getInputStream();

        // 为什么抛异常？？？
       // BufferedReader reader = new BufferedReader(new InputStreamReader(is));
       // reader.readLine();

        // 可以
       // byte[] bytes = new byte[1024];
       // is.read(bytes);
       // System.out.println(new String(bytes));

        // 可以
        Scanner scanner = new Scanner(is);
        String s = scanner.nextLine();
        System.out.println(s);

    }
}
